package com.mengma.controller;

import com.mengma.dao.ProductMapper;
import com.mengma.entity.Product;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.naming.Name;

@RestController
@RequestMapping(value = "/dd/")
public class TestProductController {

    @Autowired
    private ProductMapper productMapper;

    @PostMapping(value = "selectByPname")
    public String testSelectByPname(){
        Product product = productMapper.selectByPname("小米 4c 标准版");
        if (product == null) {
            return  "没有你要查找的嘻嘻";
        }
        return product.toString();
    }


    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "传递name的参数",required = true,dataType = "String"),
            @ApiImplicitParam(name = "sex",value = "传递sex的参数",required = false,dataType = "Integer")
    }
    )
    @PostMapping(value = "insert_test")
    public String insert_test(String name ,int sex ){
        Product product = new Product();
        product.setPid("77");
        product.setPname("xixi");

        int i = productMapper.insert_test(product);
        if (i > 0) {
            return "新增成功";
        }
        return  "新增失败";
    }


    @ApiOperation("描述")
    @PostMapping(value = "select")
    public String select(@RequestBody Product product){
        Product productSelect = productMapper.findProductSelect(product);
        System.out.println(productSelect.toString()+"lasdjflajsdflj");
        // TODO ！！！！
        return productSelect.toString();
    }

}
